package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tanhua.dubbo.mapper.UserMapper;
import com.tanhua.model.domian.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class UserApiImpl implements UserApi{

    @Autowired
    private UserMapper userMapper;

    @Override
    public User findByMobile(String verificationCode) {
        return userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getMobile,verificationCode));
    }

    @Override
    public Long save(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }

    @Override
    public List<User> findAll() {
        return userMapper.selectList(Wrappers.emptyWrapper());
    }

    @Override
    public User findById(Long userId) {
        User user = userMapper.selectById(userId);
        return user;
    }

    @Override
    public User findHuanxinId(String huanxinId) {
        LambdaQueryWrapper<User> uqw = new LambdaQueryWrapper<>();
        if (huanxinId != null){
            uqw.eq(User::getHxUser,huanxinId);
            User user = userMapper.selectOne(uqw);
            return user;
        }
        return null;
    }


}
